package org.nkumar.mesex;

import net.sourceforge.pmd.ast.ASTCompilationUnit;
import net.sourceforge.pmd.ast.CompilationUnit;
import net.sourceforge.pmd.parsers.Parser;
import net.sourceforge.pmd.sourcetypehandlers.Java15Handler;
import net.sourceforge.pmd.sourcetypehandlers.JavaTypeHandler;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.Map;
import java.util.HashMap;

public final class MessageExtractor
{
    private MessageExtractor()
    {
    }

    public static void main(String[] args) throws Exception
    {
        final JavaTypeHandler typeHandler = new Java15Handler();
        Parser parser = typeHandler.getParser();
        Reader reader = new BufferedReader(new FileReader(new File(args[0])));
        CompilationUnit rootNode = (CompilationUnit) parser.parse(reader);
        typeHandler.getSymbolFacade().start(rootNode);

        typeHandler.getTypeResolutionFacade(MessageExtractor.class.getClassLoader()).start(rootNode);
        Map<String, String> messages = new HashMap<String, String>();
        new MesExRule(messages, MesExRuleMetadataFactory.createEasyLoggerMesExRuleMetadata())
                .visit((ASTCompilationUnit) rootNode, null);
        System.out.println("messages = " + messages);
    }
}
